package com.zjhn.ds.controller.app.pad;

import com.alibaba.fastjson.JSON;
import com.zjhn.ds.common.BizResult;
import com.zjhn.ds.domain.dto.pad.*;
import com.zjhn.ds.param.*;
import com.zjhn.ds.service.ProTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.controller.app.pad
 * @Author: sxt
 * @CreateTime: 2023-09-23  10:20
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/jlw/proTask")
@Api(tags = "pad端生产单接口")
public class ProTaskController {

    @Resource
    private ProTaskService proTaskService;

    @ApiOperation("获取生产单信息")
    @PostMapping("/getProTaskList")
    public BizResult<List<ProTaskDto>> getProTaskList(@RequestBody @Valid GetProTaskParam param) {
        log.info("====[INFO]========ProTaskController====getProTaskList param:{}", JSON.toJSONString(param));
        return proTaskService.getProTaskList(param);
    }

    @ApiOperation("获取生产单明细")
    @GetMapping("/getProTaskDetails")
    public BizResult<List<ProTaskDetailDto>> getProTaskDetails(@RequestParam("pro_task_id") String proTaskId) {
        log.info("====[INFO]========ProTaskController====getProTaskDetails proTaskId:{}", proTaskId);
        return proTaskService.getProTaskDetails(proTaskId);
    }

    @ApiOperation("设置明细班次产量和预警值")
    @PostMapping("/setProduceAndWarn")
    public BizResult<?> setProduceAndWarn(@RequestBody @Valid SetProduceAndWarnParam param) {
        log.info("====[INFO]========ProTaskController====setProduceAndWarn param:{}", JSON.toJSONString(param));
        return proTaskService.setProduceAndWarn(param);
    }

    @ApiOperation("获取明细班次产量和预警值")
    @GetMapping("/getProduceAndWarn")
    public BizResult<GetProduceAndWarnDto> getProduceAndWarn(
            @RequestParam("pro_task_detail_id") String proTaskDetailId,
            @RequestParam("workshop_id") String workshopId
    ) {
        log.info("====[INFO]========ProTaskController====getProduceAndWarn proTaskDetailId:{}, workshopId:{}", proTaskDetailId, workshopId);
        return proTaskService.getProduceAndWarn(proTaskDetailId, workshopId);
    }

    @ApiOperation("添加工位 获取车间工位信息")
    @PostMapping("/getStationList")
    public BizResult<List<AddStationDto>> getStationList(@RequestBody @Valid GetStationListParam param) {
        log.info("====[INFO]========ProTaskController====getStationList param:{}", JSON.toJSONString(param));
        return proTaskService.getStationList(param);
    }

    @ApiOperation("获取明细已派工工位信息")
    @GetMapping("/detailStation")
    public BizResult<List<DetailStationDto>> detailStation(@RequestParam("pro_task_detail_id") String proTaskDetailId) {
        log.info("====[INFO]========ProTaskController====detailStation proTaskDetailId:{}", proTaskDetailId);
        return proTaskService.detailStation(proTaskDetailId);
    }

    @ApiOperation("明细工位派工任务删除")
    @GetMapping("/removeAssignTask")
    public BizResult<?> removeAssignTask(@RequestParam("assign_task_id") String assignTaskId) {
        log.info("====[INFO]========ProTaskController====removeAssignTask assignTaskId:{}", assignTaskId);
        return proTaskService.removeAssignTask(assignTaskId);
    }

    @ApiOperation("批量派工")
    @PostMapping("/assignTaskBatch")
    public BizResult<?> assignTaskBatch(@RequestBody @Valid AssignTaskParam param) {
        log.info("====[INFO]========ProTaskController====assignTaskBatch param:{}", JSON.toJSONString(param));
        return proTaskService.assignTaskBatch(param);
    }


    @ApiOperation("生产单任务结束")
    @GetMapping("/proTaskFinish")
    public BizResult<?> proTaskFinish(@RequestParam("pro_task_id") String proTaskId) {
        log.info("====[INFO]========ProTaskController====proTaskFinish proTaskId:{}", proTaskId);
        return proTaskService.proTaskFinish(proTaskId);
    }

}
